import { Request,Response,NextFunction } from "express"

export const sort = async (request:Request,response:Response,next:NextFunction)=>{
    const {sort} = request.query

    let sqlSort : string
    switch(sort){
        case 'earliest':
            sqlSort = 'post.id ASC'
            break;
        case 'latest':
            sqlSort = 'post.id DESC'
            break;
        case 'most_comments':
            sqlSort = 'totalComments DESC,post.id DESC'
            break;
        default :
            sqlSort = 'post.id DESC'
            break;
    }
    request.sort = sqlSort
    next();
}

export const filter = async (request:Request,response:Response,next:NextFunction)=>{
    console.log(request.sort)
}

export const paginate = async (request:Request,response:Response,next:NextFunction)=>{

}